<template>
  <div class="container" >
    <!--@click="clickHandle('test click', $event)"-->
    <IndexSwiper :images="IndexInfo.banner"> </IndexSwiper>
    <MiddleNav :navlists="IndexInfo.nav"> </MiddleNav>

    <JobList :list="jobList"> </JobList>

    <Contact> </Contact>

    <div class="end-flag end-flag-loding" v-show="isLoading === true">正在加载中...</div>

    <div class="end-flag end-flag-isnext" v-show="isNext === false">已加载全部</div>
    <!--<a href="/pages/counter/main" class="counter">去往Vuex示例页面</a>-->
  </div>
</template>

<script>
const wxapp = getApp();

import card from '@/components/card'
import IndexSwiper from '@/components/Index/IndexSwiper'
import MiddleNav from '@/components/Index/MiddleNav'
import JobList from '@/components/Index/JobList'
import Contact from '@/components/contact'
export default {
  data () {
    return {
      IndexInfo: {},
      userInfo: {},
      imgSrc : '../../../static/swiper1.jpg',
      isLoading : false,
      isNext: true,
      jobList : [
        {thumb : '../../static/compicture.png' ,title:'苏州极鼎网络科技有限公司',description:'18-45岁/男女不限/无不良嗜好',money:'5000-8000',dizhi:'江苏-昆山',type:'小时工'},
        {thumb : '../../static/compicture.png' ,title:'苏州极鼎网络科技',description:'18-45岁/男女不限/无不良嗜好',money:'5000-8000',dizhi:'江苏-昆山',type:'返现'},
        {thumb : '../../static/compicture.png' ,title:'苏州极鼎网络科技有限公司',description:'18-45岁/男女不岁/男女不岁/男女不岁/男女不岁/男女不限/无不良嗜好',money:'5000-8000',dizhi:'江苏-昆山',type:'小时工'},
        {thumb : '../../static/compicture.png' ,title:'苏州极鼎网络科技有限公有限公科技有限公有限公科技有限公有限公科技有限公有限公有限公有限公有限公司',description:'18-45岁/男女不限/无不良嗜好',money:'5000-8000',dizhi:'江苏-昆山',type:'小时工'},
      ],
      page: 1
    }
  },

  components: {
    card,
    IndexSwiper,
    MiddleNav,
    JobList,
    Contact
  },
  onReachBottom(){
    console.log('首页滑动到底部');
    if(this.isLoading == true || this.isNext != true){
      return;
    }
    this.isLoading = true;
    this.page += 1
    this.getList()
  },
  methods: {
    bindViewTap () {
      const url = '../logs/main';
      wx.navigateTo({ url })
    },
    getUserInfo () {
      // 调用登录接口
      wx.login({
        success: () => {
          wx.getUserInfo({
            success: (res) => {
              console.log(res);

              this.userInfo = res.userInfo
            }
          })
        }
      })
    },
    getIndex() {
      wx.showLoading({
        title: '加载中',
      })
      let that = this
      wx.request({
        url: wxapp.globalData.ROOT_URL, //仅为示例，并非真实的接口地址
        data: {
           siteid: '4' ,
           service: 'App.Hong.IndexInfo'
        },
        header: {
            'content-type': 'application/json' // 默认值
        },
        success: function(res) {
          that.IndexInfo = res.data.data.result
          wx.hideLoading()
        }
      })
    },
    getList() {
      wx.showLoading({
        title: '加载中',
      })
      let that = this
      wx.request({
        url: wxapp.globalData.ROOT_URL, //仅为示例，并非真实的接口地址
        data: {
           siteid: '4' ,
           service: 'App.Hong.Index',
           page: that.page,
           table: '4_jobs',
           ftable: '4_jobs_category',
           where: {
             tui: 1
           }
        },
        success: function(res) {
          wx.hideLoading()
          that.isLoading = false
          if(res.data.data.result == 0) {
            wx.showToast({
              title: '没有了',
              icon: 'success',
              duration: 2000
            })
            that.isNext = false
          }else {
            let list = res.data.data.result
            if(that.page >1) {
              let jobList = that.jobList
              for(let i in list) {
                jobList.push(list[i])
              }
              that.jobList = jobList
            }else {
              that.jobList = list
            }
          }

        }
      })
    }
    // clickHandle (msg, ev) {
    //   // console.log('clickHandle:', msg, ev)
    // }
  },


  created () {
    // 调用应用实例的方法获取全局数据
    this.getIndex()
    this.getList()
console.log(wxapp.globalData.base);
  }

}
</script>

<style scoped>


</style>
